//
//  DiscoveryTableViewController.swift
//  Hunter
//
//  Created by oher on 15/6/24.
//  Copyright © 2015年 刘🐑. All rights reserved.
//

import UIKit

class DiscoveryTableViewController: UIViewController {
    
    var toolBar : XVToolBar?

    override func viewDidLoad() {
        super.viewDidLoad()
        //导航栏rightBarButton设置
        navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named:"distriDynamic"), style: UIBarButtonItemStyle.Plain, target: self, action: "add")
        view.backgroundColor = UIColor.whiteColor()
        
        //工具栏
        addToolBar()

        //ScrollView
        addScrollView()
        
    }
    
    ///ScrollView
    func addScrollView(){
        let scrollView = UIScrollView()
        
        let w = UIScreen.mainScreen().bounds.width
        let y = CGRectGetMaxY((toolBar?.frame)!)
        let h = UIScreen.mainScreen().bounds.height - y - 44
        
        scrollView.frame = CGRectMake(0, y, w, h)
        scrollView.contentSize = CGSizeMake(w*2 , h)
        scrollView.pagingEnabled = true
        scrollView.bounces = false
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.backgroundColor = UIColor.grayColor()
        view.addSubview(scrollView)
        
        
        //TODO:change into self difine tableView
        let tab1 = UITableView()
        tab1.frame = CGRectMake(0, 0, w, h)
        scrollView.addSubview(tab1)
        
        let tab2 = UITableView()
        tab2.frame = CGRectMake(w, 0, w, h)
        scrollView.addSubview(tab2)
        
    }
    
    ///工具栏
    func addToolBar(){
        let toolBar =  NSBundle.mainBundle().loadNibNamed("XVToolBar", owner: nil, options: nil).last as! XVToolBar
        view.addSubview(toolBar)
        //toolBar
        toolBar.translatesAutoresizingMaskIntoConstraints = false
        view.addConstraint(NSLayoutConstraint(item: toolBar, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[subView]|", options: NSLayoutFormatOptions.AlignAllBaseline, metrics: nil, views: ["subView": toolBar]))
        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[subView(40)]", options: NSLayoutFormatOptions.AlignAllBaseline, metrics: nil, views: ["subView":toolBar]))
        
        self.toolBar = toolBar
        
    }
    
    func add(){
        print(__FUNCTION__)
    }
    

}
